var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/businessComponent/download-excel/index.tsx
var download_excel_exports = {};
__export(download_excel_exports, {
  DownloadExcel: () => DownloadExcel
});
module.exports = __toCommonJS(download_excel_exports);
var import_icons = require("@ant-design/icons");
var import_antd = require("antd");
var import_react = __toESM(require("react"));
var import_configComponent = require("../../configComponent");
var import_functionalComponent = require("../../functionalComponent");
var import_util = require("../../util");
var import_grid = require("../grid");
var import_constVar = require("./constVar");
var import_services = require("./services");
var { Flex } = import_util.Layout;
var DownloadExcel = ({ state }) => {
  const { keyCode } = state;
  const formRef = (0, import_util.useApi)();
  const gridRef = (0, import_util.useApi)();
  const [value, setValue] = (0, import_react.useState)({});
  const [loading, setLoading] = (0, import_react.useState)(false);
  const [showModal, setShowModal] = (0, import_react.useState)(false);
  const request = (0, import_react.useMemo)(
    () => async () => {
      var _a;
      if (showModal && keyCode) {
        const rc = await (0, import_services.getByBizCode)({ bizCode: keyCode });
        setValue({ ...rc.data });
        return (((_a = rc.data) == null ? void 0 : _a.dtlList) || []).map((it) => ({ ...it, init: it.mustInput }));
      }
      return [];
    },
    [showModal]
  );
  const save = async () => {
    var _a, _b;
    const tableData = gridRef.current.getApi().getData();
    if (!((_b = (_a = gridRef.current.getApi()).validData) == null ? void 0 : _b.call(_a))) {
      import_util.iup.alert("保存失败,请检查必填项是否填写!");
      return;
    }
    setLoading(true);
    const rc = await (0, import_services.exportTemplate)({
      fileName: "excel",
      idList: tableData.filter((it) => it.mustInput).map((it) => it.id)
    });
    setLoading(false);
    if (rc == null ? void 0 : rc.message) {
      import_util.iup.alert(rc.message);
    } else {
      import_util.iup.downLoad({
        blob: base64toBlob(rc),
        filename: "导入.xls"
      });
      import_util.iup.alert("导出成功");
      setShowModal(false);
    }
  };
  const base64toBlob = (base64) => {
    const bstr = window.atob(base64);
    let n = bstr.length;
    const u8arr = new Uint8Array(n);
    while (n--) {
      u8arr[n] = bstr.charCodeAt(n);
    }
    return new Blob([u8arr], { type: "application/vnd.ms-excel" });
  };
  const close = () => {
    setShowModal(false);
  };
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(import_functionalComponent.Button, { onClick: () => setShowModal(true), key: "edit" }, "模版编辑"), /* @__PURE__ */ import_react.default.createElement(
    import_antd.Drawer,
    {
      title: "模版编辑",
      width: 700,
      closable: false,
      onClose: close,
      open: showModal,
      destroyOnClose: true,
      zIndex: 995,
      extra: /* @__PURE__ */ import_react.default.createElement(import_icons.CloseOutlined, { onClick: close }),
      footer: /* @__PURE__ */ import_react.default.createElement("div", { style: { display: "flex", justifyContent: "flex-end" } }, /* @__PURE__ */ import_react.default.createElement(import_functionalComponent.Button, { style: { marginRight: 10 }, onClick: close }, "取消"), /* @__PURE__ */ import_react.default.createElement(import_functionalComponent.Button, { type: "primary", onClick: save, loading }, "模版导出"))
    },
    /* @__PURE__ */ import_react.default.createElement(import_util.Layout, null, /* @__PURE__ */ import_react.default.createElement(import_configComponent.Form, { id: "excelModel", ref: formRef, colspan: 2, value, config: import_constVar.opFormConfig, disabled: true }), /* @__PURE__ */ import_react.default.createElement(Flex, null, /* @__PURE__ */ import_react.default.createElement(
      import_grid.Grid,
      {
        busKey: "id",
        ref: gridRef,
        bordered: true,
        editColumnIcon: true,
        headerMenu: false,
        showRowNumber: true,
        columns: import_constVar.opFormColumns,
        request
      }
    )))
  ));
};
(0, import_util.registerComponent)({ DownloadExcel });
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  DownloadExcel
});
